
import 'package:flutter/material.dart';

/// 用于提供全局的 GlobalKey
/*
MaterialApp(
        navigatorKey: GlobalKeyProvider.navigatorKey,
        home: HomePage(),
      ),
 */
class GlobalKeyProvider{
  final GlobalKey<NavigatorState> _navigatorKey = GlobalKey<NavigatorState>();

  static final GlobalKeyProvider _instance = GlobalKeyProvider._();

  GlobalKeyProvider._();

  /// 赋值给根布局的 materialApp 上
  static GlobalKey<NavigatorState> get navigatorKey => _instance._navigatorKey;

  static BuildContext? get navigatorContext => _instance._navigatorKey.currentState?.context;
}